package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.MemberEntity;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;
import com.runen.rxnetlibrary.utils.TimeUtil;
import com.runen.rxnetlibrary.utils.ToastUtils;

/**
 * Create by LiaoDuanHong
 * Create on 2021/02/28 15:52
 */
public class MemberListAdapter extends BaseQuickAdapter<MemberEntity.DataBean.TeamMemberListBean, BaseViewHolder> {
    private Context context;
    private String createTime = "加入时间：%s";
    private int type = 0;
    private int point = -1;

    public void setPoint(int point) {
        this.point = point;
    }

    public MemberListAdapter(Context context) {
        super(R.layout.include_member_list_info);
        this.context = context;
    }

    public MemberListAdapter(Context context, int type) {
        super(R.layout.include_member_list_info);
        this.context = context;
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, MemberEntity.DataBean.TeamMemberListBean item) {
        ImageView iv_check = baseViewHolder.getView(R.id.iv_check);
        RoundedCornersImage rciCaptainHeader = baseViewHolder.getView(R.id.rci_captain_header);
        if (TextUtils.isEmpty(item.headImgUrl)) {
            GlideUtils.loadImage(context, R.mipmap.ico_person_head, rciCaptainHeader);
        } else {
            GlideUtils.loadImage(context, item.headImgUrl, rciCaptainHeader);
        }
        baseViewHolder.setText(R.id.tv_member_name, item.nickname);
        baseViewHolder.setText(R.id.tv_time, String.format(createTime, TimeUtil.dealDateFormat2(item.createTime)));
        baseViewHolder.setText(R.id.tv_hozom_num, item.tinder + "颗");
        View vLine = baseViewHolder.getView(R.id.v_line);
        vLine.setVisibility(View.VISIBLE);
        if (type == 2) {
            iv_check.setVisibility(View.VISIBLE);
            if (point == baseViewHolder.getAdapterPosition()) {
                iv_check.setImageResource(R.mipmap.ico_person_checked);
            } else {
                iv_check.setImageResource(R.mipmap.ico_person_normal_check);
            }
        } else {
            iv_check.setVisibility(View.GONE);
        }

    }
}
